﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using CommonObjects.LeasingLogic;
using CommonObjects.Printing;

namespace TestApplication
{
    public partial class frmMain : Form
    {


        public frmMain()
        {
            InitializeComponent();
             


            cmbTokeFiz.DataSource = Enum.GetNames(typeof(Gyak));
            cmbKamatFiz.DataSource = Enum.GetNames(typeof(KamatGyak));
            cmbKezKtg.DataSource = Enum.GetNames(typeof(Gyak));
            cmbKalkType.DataSource = Enum.GetNames(typeof(KalkTipus));
            
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {


        }



        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            try 
            {
                Convert.ToDouble(txtHitelOsszeg.Text);
            }
            catch 
            {
                bool b = txtHitelOsszeg.Focus();
                MessageBox.Show("Számadatot adjon meg!");
            }
            finally
            {
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            grid1.Rows.Clear();
            headerGrid.Rows.Clear();

            grid1.ColumnsCount = Enum.GetValues(typeof(OszlopFejlec)).Length;
            grid1.FixedRows = 1;
            grid1.Rows.Insert(0);

            headerGrid.ColumnsCount = 3;
            headerGrid.Rows.Insert(0);
            headerGrid.Columns[0].Width = 300;
            headerGrid.Columns[1].Width = 90;

            StringEnum es = new StringEnum(typeof(OszlopFejlec));

            KalkTipus KT;
            KT = (KalkTipus)Enum.Parse(typeof(KalkTipus), cmbKalkType.Text);
            //MessageBox.Show((int)KT.ToString());

            for (int cy = 0; cy <= Enum.GetValues(typeof(OszlopFejlec)).Length - 1; cy++)
            {
                grid1[0, cy] = new SourceGrid.Cells.ColumnHeader(es.GetStringValue(Enum.GetName(typeof(OszlopFejlec), cy+1)));
            }

            for (int col = 0; col <= grid1.Columns.Count-1; col++)
            {
                if (col == 0) {
                    grid1.Columns[col].Width = 35;
                } else {
                grid1.Columns[col].Width = 90;
                }
            }

            CalcInputData ci;
            ci = new CalcInputData();
            ci.FinanszirozottOsszeg = Convert.ToDouble(txtHitelOsszeg.Text);
            ci.Futamido = Convert.ToInt16(txtFutamIdo.Text);
            ci.Kamat = Convert.ToDouble(txtKamat.Text);
            ci.KezKtg = Convert.ToDouble(txtKezKtg.Text);
            ci.KezelKtgMax = Convert.ToDouble(txtKezKtgMax.Text);
            ci.KezelKtgMin = Convert.ToDouble(txtKezKtgMin.Text);
            ci.TokeFizGyak = (new HelperClasses()).getGyakEnumByName(cmbTokeFiz.Text);
            ci.KamatFizGyak = (new HelperClasses()).getGyakEnumByName(cmbKamatFiz.Text);
            ci.KezKtgFizGyak = (new HelperClasses()).getGyakEnumByName(cmbKezKtg.Text);
            ci.Arfolyam = Convert.ToDouble(txtArfolyam.Text);
            ci.Deviza = cmbDeviza.Text;
            ci.FolyKtgSZ = Convert.ToDouble(txtFolySzazalek.Text);
            ci.FolyKtgMax = Convert.ToDouble(txtFolyMax.Text);
            ci.FolyKtgMin = Convert.ToDouble(txtFolyMin.Text);
            ci.FolyJutBe = chkFolyJutBe.Checked;

            ci.HitelBirSZ = Convert.ToDouble(txtHitelBirSzaz.Text);
            ci.HitelBirERT = Convert.ToDouble(txtHitelBirErt.Text);
            ci.HitBirBe = chkHitBirBe.Checked;

            ci.ErtekBecslERT = Convert.ToDouble(txtErtBecsErt.Text);
            ci.ErtekBecslSZ = Convert.ToDouble(txtErtBecsSZ.Text);
            ci.ErtBecsBe = chkErtBecsBe.Checked;

            ci.HelySzemleSZ = Convert.ToDouble(txtHelySzemlSZ.Text);
            ci.HelySzemleERT = Convert.ToDouble(txtHelySzemlErt.Text);
            ci.HelySzemBe = chkHelySzemBe.Checked;
            
            

            Calculation c;
            c = new Calculation((int)KT, ci);

            if (!c.KalkEredmeny()) { MessageBox.Show("Hibás kalkuláció típus"); }

            //Fejléc
            if (c.COD.Fejlec.Count > 0)
            {
                for (int r = 0; r <= c.COD.Fejlec.Count - 1; r++)
                {
                    headerGrid.Rows.Insert(r);
                    for (int cy = 0; cy <= 1; cy++)
                    {
                        switch (cy)
                        {
                            case 0:
                                {
                                    headerGrid[r, cy] = new SourceGrid.Cells.Cell(c.GetFejlecSor(r).KoltsegNeve, typeof(string));
                                    break;
                                }
                            case 1:
                                {
                                    headerGrid[r, cy] = new SourceGrid.Cells.Cell(c.GetFejlecSor(r).KoltsegOsszegSTR, typeof(string));
                                    break;
                                }
                        }
                        System.Drawing.Font fo = headerGrid.Rows[r].Grid.Font;
                        if (c.GetFejlecSor(r).Bold)
                        {
                            System.Drawing.Font f = new System.Drawing.Font(headerGrid.Rows[r].Grid.Font, System.Drawing.FontStyle.Bold);

                            headerGrid.Rows[r].Grid.Font = f;
                        }
                        else
                        {
                            headerGrid.Rows[r].Grid.Font = fo;
                        }

                    }

                }
            }
            //eredmény

            for (int r = 1; r <= c.COD.Eredmeny.Count; r++)
            {
                grid1.Rows.Insert(r);
                for (int cy = 0; cy <= Enum.GetValues(typeof(OszlopFejlec)).Length - 1; cy++)
                {
                    grid1[r, cy] = new SourceGrid.Cells.Cell(c.GetEredmeny(r - 1).getStrOszlopAdat(Enum.GetName(typeof(OszlopFejlec), cy + 1)), typeof(string));
                    grid1[r, cy].View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight;
                }

            }

            txtTHM.Text = c.COD.THM.ToString() + " %";

        }

        private void txtFutamIdo_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                Convert.ToDouble(txtFutamIdo.Text);
            }
            catch
            {
                bool b = txtFutamIdo.Focus();
                MessageBox.Show("Számadatot adjon meg!");
            }
            finally
            {
            }
        }

        private void txtKamat_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                Convert.ToDouble(txtKamat.Text);
            }
            catch
            {
                bool b = txtKamat.Focus();
                MessageBox.Show("Számadatot adjon meg!");
            }
            finally
            {
            }
        }

        private void cmbKezKtg_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            doPrintToRTF rt = new doPrintToRTF();
            rt.doRTF();

        }




    }
}
